home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Panel Editor / Source / FrameInfo.cpp < prev    next >
Encoding:
Text File  |  1995-12-08  |  11.7 KB  |  406 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FrameInfo.cpp
  3.  
  4.     Contains:    FrameInfo utility class
  5.  
  6.     Written by:    Steve Smith
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. // -- OpenDoc Utilities --
  18.  
  19. #ifndef _EXCEPT_
  20. // Exceptions define several important macros (ie. CHECKENV)
  21. // which are used in the SOM method dispatch glue. If Except.h
  22. // is not included early enough, exceptions may not be thrown
  23. // correctly when returning from a SOM method with "ev" parameter set.
  24. #include <Except.h>
  25. #endif
  26.  
  27. // --- FrameInfo Includes ---
  28.  
  29. #ifndef _FRAMEINFO_
  30. #include "FrameInfo.h"
  31. #endif
  32.  
  33. #ifndef _PANELEDITORDEF_
  34. #include "PanelEditorDef.h"
  35. #endif
  36.  
  37. // --- OpenDoc Includes ---
  38.  
  39. #ifndef _ODTYPES_
  40. #include <ODTypes.h>
  41. #endif
  42.  
  43. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  44. #include <StdDefs.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODFrame_xh
  48. #include <Frame.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODStorageUnit_xh
  52. #include <StorageU.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODStorageUnitView_xh
  56. #include <SUView.xh>
  57. #endif
  58.  
  59. #ifndef SOM_ODDraft_xh
  60. #include <Draft.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODWindowState_xh
  64. #include <WinStat.xh>
  65. #endif
  66.  
  67. // -- OpenDoc Utilities --
  68.  
  69. #ifndef _ISOSTR_
  70. #include <ISOStr.h>
  71. #endif
  72.  
  73. #ifndef _ODNEW_
  74. #include <ODNew.h>
  75. #endif
  76.  
  77. #ifndef _ODUTILS_
  78. #include <ODUtils.h>
  79. #endif
  80.  
  81. #ifndef _TEMPOBJ_
  82. #include <TempObj.h>
  83. #endif
  84.  
  85. #ifndef _STORUTIL_    
  86. #include <StorUtil.h>
  87. #endif
  88.  
  89. #pragma segment PanelEditorFramInfo
  90.  
  91. //=========================================================================
  92. // CFrameInfo
  93. //=========================================================================
  94.  
  95. //-------------------------------------------------------------------------
  96. // CFrameInfo::CFrameInfo
  97. //-------------------------------------------------------------------------
  98.  
  99. CFrameInfo::CFrameInfo(ODSession* session)
  100. {
  101.     fSession = session;
  102.     fFrameActive = kODFalse;
  103.     fFrameReactivate  = kODFalse;
  104.     fShouldDisposeWindow = kODFalse;
  105.     fActiveFacet = kODNULL;
  106.     fSourceFrame = kODNULL;
  107.     fDependentFrame = kODNULL;
  108.     fPartWindowID = kODNULLID; 
  109.     fPreviousViewType = kODNullTypeToken;
  110.     fShouldNegotiate = kODFalse;
  111. }
  112.  
  113. //-------------------------------------------------------------------------
  114. // CFrameInfo::~CFrameInfo
  115. //-------------------------------------------------------------------------
  116.  
  117. CFrameInfo::~CFrameInfo()
  118. {
  119.     // Deleting the proxies will release the encapsulated frames.
  120.     ODDeleteObject(fDependentFrame);
  121.     ODDeleteObject(fSourceFrame);
  122. }
  123.  
  124. //-------------------------------------------------------------------------
  125. // CFrameInfo::Externalize
  126. //-------------------------------------------------------------------------
  127.  
  128. void CFrameInfo::Externalize(Environment* ev, ODStorageUnitView* storageUnitView)
  129. {
  130.     // This method assumes that OpenDoc has passed us a storageUnitView
  131.     // that is focused to a property, but no particular value.
  132.     
  133.     ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
  134.  
  135.     this->CleanseFrameInfoProperty(ev, storageUnit);
  136.     this->ExternalizeFrameInfo(ev, storageUnit, kODNULLKey, kODNULL);
  137. }
  138.  
  139. //-------------------------------------------------------------------------
  140. // CFrameInfo::CleanseFrameInfoProperty
  141. //-------------------------------------------------------------------------
  142.  
  143. void CFrameInfo::CleanseFrameInfoProperty(Environment* ev, ODStorageUnit* storageUnit)
  144. {
  145.     ODULong numValues;
  146.     ODULong index;
  147.         
  148.     numValues = storageUnit->CountValues(ev);
  149.     
  150.     for (index = numValues; index >= 1; index--)
  151.     {
  152.         // Index, from 1 to n, through the values.
  153.         storageUnit->Focus(ev, kODNULL, kODPosSame, 
  154.                                 kODNULL, index, kODPosUndefined);
  155.                                 
  156.         // Get the ISO type name for the value. The temp object
  157.         // will automatically delete the returned value when this
  158.         // scope is exited.
  159.         TempODValueType value = storageUnit->GetType(ev);
  160.         
  161.         // If the value type is not one we support, remove it.
  162.         if ( ODISOStrCompare(value, kPanelEditorInfo) != 0 )
  163.             storageUnit->Remove(ev);
  164.     }
  165. }
  166.  
  167. //-------------------------------------------------------------------------
  168. // CFrameInfo::ExternalizeFrameInfo
  169. //-------------------------------------------------------------------------
  170.  
  171. void CFrameInfo::ExternalizeFrameInfo(Environment* ev, ODStorageUnit* storageUnit,
  172.                                         ODDraftKey key, ODFrame* scopeFrame)
  173. {
  174.     // This method behaves much the same way as the SamplePart::ExternalizeStateInfo
  175.     // method.
  176.     
  177.     if ( storageUnit->Exists(ev, kODNULL, kPanelEditorInfo, 0) )
  178.     {
  179.         // Persistent object references are stored in a side table, rather than
  180.         // in the property/value stream. Thus, deleting the contents of a value
  181.         // will not "delete" the references previously written to that value. To
  182.         // completely "delete" all references written to the value, we must
  183.         // remove the value and add it back.
  184.  
  185.         storageUnit->Focus(ev, kODNULL, kODPosSame, kPanelEditorInfo, 0, kODPosUndefined);
  186.         storageUnit->Remove(ev);
  187.     }
  188.  
  189.     // Add a value to write the data into.
  190.     storageUnit->AddValue(ev, kPanelEditorInfo);
  191.     
  192.     // Write a weak reference to our source frame.
  193.     {
  194.         ODStorageUnitRef weakRef = {0,0,0,0};
  195.         
  196.         if ( fSourceFrame )
  197.         {
  198.             ODID        frameID = fSourceFrame->GetID();
  199.             ODID        scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : kODNULLID );
  200.             ODDraft*    fromDraft = fSourceFrame->GetDraft();
  201.     
  202.             // If a draft key exists, then we are being cloned to another draft.
  203.             // We must "weak" clone our display frame and reference the cloned
  204.             // frame. The part re-uses the frameID variable so there aren't two
  205.             // different GetWeakStorageUnitRef calls.
  206.             if ( key )
  207.                 frameID = fromDraft->WeakClone(ev, key, frameID, kODNULLID, scopeFrameID);
  208.             
  209.             // Write out weak references to each of the part's display frames.
  210.             storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
  211.         }
  212.         StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
  213.     }
  214.     
  215.     // Write a weak reference to our dependent frame.
  216.     {
  217.         ODStorageUnitRef weakRef = {0,0,0,0};
  218.         
  219.         if ( fDependentFrame )
  220.         {
  221.             ODID        frameID = fDependentFrame->GetID();
  222.             ODID        scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : kODNULLID );
  223.             ODDraft*    fromDraft = fDependentFrame->GetDraft();
  224.     
  225.             // If a draft key exists, then we are being cloned to another draft.
  226.             // We must "weak" clone our display frame and reference the cloned
  227.             // frame. The part re-uses the frameID variable so there aren't two
  228.             // different GetWeakStorageUnitRef calls.
  229.             if ( key )
  230.                 frameID = fromDraft->WeakClone(ev, key, frameID, kODNULLID, scopeFrameID);
  231.             
  232.             // Write out weak references to each of the part's display frames.
  233.             storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
  234.         }
  235.         StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
  236.     }
  237. }
  238.  
  239. //-------------------------------------------------------------------------
  240. // CFrameInfo::CloneInto
  241. //-------------------------------------------------------------------------
  242.  
  243. void CFrameInfo::CloneInto(Environment *ev, ODDraftKey key,
  244.                             ODStorageUnitView* storageUnitView, ODFrame* scopeFrame)
  245. {
  246.     // This method assumes that OpenDoc has passed us a storageUnitView
  247.     // that is focused to a property, but no particular value.
  248.     
  249.     ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
  250.  
  251.     if ( storageUnit->Exists(ev, kODNULL, kPanelEditorInfo, 0) == kODFalse )
  252.     {
  253.         this->ExternalizeFrameInfo(ev, storageUnit, key, scopeFrame);
  254.     }
  255. }
  256.  
  257. //-------------------------------------------------------------------------
  258. // CFrameInfo::InitFromStorage
  259. //------------------------------------------------------------------------------
  260.  
  261. void CFrameInfo::InitFromStorage(Environment* ev, ODStorageUnitView* storageUnitView)
  262. {
  263.     // This method assumes that OpenDoc has passed us a storageUnitView
  264.     // that is focused to a property, but no particular value.
  265.     
  266.     ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
  267.  
  268.     if ( storageUnit->Exists(ev, kODNULL, kPanelEditorInfo, 0) )
  269.     {
  270.         TRY
  271.             storageUnit->Focus(ev, kODNULL, kODPosSame,
  272.                                         kPanelEditorInfo, 0 , kODPosUndefined);
  273.     
  274.             ODStorageUnitRef weakRef = {0,0,0,0};
  275.             StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
  276.                                 (ODPtr)&weakRef);
  277.             
  278.             if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
  279.             {
  280.                 // Convert the reference into a runtime id.
  281.                 ODID frameID = storageUnit->GetIDFromStorageUnitRef(ev, weakRef);
  282.  
  283.                 // Create a proxy class to support the lazy internalization.
  284.                 CFrameProxy* proxy = new CFrameProxy;
  285.                 proxy->InitFrameProxy(frameID, ODGetDraft(ev,storageUnit));
  286.  
  287.                 // Store the proxy source frame.
  288.                 fSourceFrame = proxy;
  289.             }
  290.             
  291.         CATCH_ALL
  292.             ODDeleteObject(fSourceFrame);
  293.             fSourceFrame = kODNULL;
  294.             // We do not RERAISE because the reference is weak and therefore
  295.             // we cannot rely on its existence.
  296.         ENDTRY
  297.  
  298.         TRY
  299.             ODStorageUnitRef weakRef = {0,0,0,0};
  300.             StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
  301.                                 (ODPtr)&weakRef);
  302.             
  303.             if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
  304.             {
  305.                 // Convert the reference into a runtime id.
  306.                 ODID frameID = storageUnit->GetIDFromStorageUnitRef(ev, weakRef);
  307.  
  308.                 // Create a proxy class to support the lazy internalization.
  309.                 CFrameProxy* proxy = new CFrameProxy;
  310.                 proxy->InitFrameProxy(frameID, ODGetDraft(ev,storageUnit));
  311.  
  312.                 // Store the proxy dependent frame.
  313.                 fDependentFrame = proxy;
  314.             }
  315.             
  316.         CATCH_ALL
  317.             ODDeleteObject(fDependentFrame);
  318.             fDependentFrame = kODNULL;
  319.             // We do not RERAISE because the reference is weak and therefore
  320.             // we cannot rely on its existence.
  321.         ENDTRY
  322.     }
  323. }
  324.  
  325. //-------------------------------------------------------------------------
  326. // CFrameInfo::SetSourceFrame
  327. //-------------------------------------------------------------------------
  328.  
  329. void CFrameInfo::SetSourceFrame(Environment* ev, ODFrame* frame)
  330. {
  331.     if ( frame != kODNULL )
  332.     {
  333.         // Create a proxy class to support the lazy internalization.
  334.         CFrameProxy* proxy = new CFrameProxy;
  335.         proxy->InitFrameProxy(ev,frame);
  336.         
  337.         // Store the proxy source frame after clearing the old one.
  338.         ODDeleteObject(fSourceFrame);
  339.         fSourceFrame = proxy;
  340.     }
  341. }
  342.  
  343. //-------------------------------------------------------------------------
  344. // CFrameInfo::ReleaseSourceFrame
  345. //-------------------------------------------------------------------------
  346.  
  347. void CFrameInfo::ReleaseSourceFrame(Environment* ev)
  348. {
  349.     ODDeleteObject(fSourceFrame);
  350. }
  351.  
  352. //-------------------------------------------------------------------------
  353. // CFrameInfo::SetDependentFrame
  354. //-------------------------------------------------------------------------
  355.  
  356. void CFrameInfo::SetDependentFrame(Environment* ev, ODFrame* frame)
  357. {
  358.     if ( frame != kODNULL )
  359.     {
  360.         // Create a proxy class to support the lazy internalization.
  361.         CFrameProxy* proxy = new CFrameProxy;
  362.         proxy->InitFrameProxy(ev,frame);
  363.         
  364.         // Store the proxy dependent frame after clearing the old one.
  365.         ODDeleteObject(fDependentFrame);
  366.         fDependentFrame = proxy;
  367.     }
  368. }
  369.  
  370. //-------------------------------------------------------------------------
  371. // CFrameInfo::ReleaseDependentFrame
  372. //-------------------------------------------------------------------------
  373.  
  374. void CFrameInfo::ReleaseDependentFrame(Environment* ev)
  375. {
  376.     ODDeleteObject(fDependentFrame);
  377. }
  378.  
  379. //-------------------------------------------------------------------------
  380. // CFrameInfo::AcquirePartWindow
  381. //-------------------------------------------------------------------------
  382.  
  383. ODWindow* CFrameInfo::AcquirePartWindow(Environment* ev)
  384. {
  385.     ODWindow* window = kODNULL;
  386.     
  387.     if ( fPartWindowID )
  388.     {
  389.         window = fSession->GetWindowState(ev)->AcquireWindow(ev,fPartWindowID);
  390.         if ( !window) fPartWindowID = kODNULLID;
  391.     }
  392.     
  393.     return window;
  394. }
  395.  
  396. //-------------------------------------------------------------------------
  397. // CFrameInfo::SetPartWindow
  398. //-------------------------------------------------------------------------
  399.  
  400. void CFrameInfo::SetPartWindow(Environment* ev, ODWindow* window)
  401. {
  402.     fPartWindowID = window ? window->GetID(ev) : kODNULLID;
  403. }
  404.  
  405.  
  406.